#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>

int main(int argc, char** argv)
{
	if(argc < 2)
	{
		printf("input<%s file>\n",argv[0]);
		return -1;
	}
	int fd = open(argv[1],O_RDONLY);
	if(fd == -1)
	{
		perror("open");
		return -1;
	}
	char c = '\0';
	char *cp = &c;
	int cont = 0;
	while(read(fd,cp,sizeof(char)))
	{
		if(c == '\n')
			cont++;
	}
	printf("文件一共有 %d 行\n",cont);

	close(fd);
	return 0;
}
